<?php

namespace Swoole\Cache;

/**
 * Memcache封装类，支持memcache和memcached两种扩展
 * @author Tianfeng.Han
 * @package Swoole
 * @subpackage cache
 */
class SaeMemcache implements \Swoole\IFace\Cache {

	public $multi = false;
	// 启用压缩
	public static $compress = MEMCACHE_COMPRESSED;

	public $cache;

	public function __construct($configs) {
		$this->cache =\memcache_init();
		if ($this->cache === false) {
			throw new \Exception("SaeMemcache init fail", 1);
		}
	}

	/**
	 * 获取数据
	 * @see libs/system/ICache#get($key)
	 */
	public function get($key) {
		return $this->cache->get($key);
	}

	public function set($key, $value, $expire = 0) {
		return $this->cache->set($key, $value, self::$compress, $expire);
	}

	public function delete($key) {
		return $this->cache->delete($key);
	}
}